package 每日一题;

public class 替换空格 {
    public static String replaceSpace(StringBuffer str) {
        StringBuilder sb=new StringBuilder();
        for (int i=0;i<str.length();i++){
            String s=String.valueOf(str.charAt(i));
            if(s.equals(" ")){
                sb.append("%20");
            }else {
                sb.append(s);
            }
        }
        return sb.toString();
    }

    public static void main(String[] args) {
        StringBuffer sb=new StringBuffer("We Are Happy");
        System.out.println(replaceSpace(sb));
    }
}
